package com.wwz.controller;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.wwz.pojo.Charge;
import com.wwz.pojo.query.ChargeQuery;
import com.wwz.service.IChargeService;
import com.wwz.util.EcoBootException;
import com.wwz.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 物业收费控制层
 * @date 2022/03/25 56:12:26
 */
@RestController
@RequestMapping("/manage/charge")
@Api(tags = "物业收费控制层")
public class ChargeController {

    @Resource
    private IChargeService chargeService;

    @ApiOperation("物业收费列表")
    @GetMapping("/toPage")
    public Result toPage(ChargeQuery query){
        IPage<Charge> IPage = chargeService.toPage(query);
        return Result.ok(IPage);
    }


    @ApiOperation("添加或修改收费信息")
    @PostMapping("/addOrUpdate")
    public Result addOrUpdate(@RequestBody Charge charge){

        if (StrUtil.isAllEmpty(
                charge.getChargeType(),
                charge.getMoney(),
                charge.getHouseUser(),
                charge.getMoney())){
            throw new EcoBootException("请输入正确信息");
        }
        chargeService.addOrUpdate(charge);
        return Result.ok("ok");
    }


    @ApiOperation("删除物业收费信息")
    @DeleteMapping("delete/{id}")
    public Result delete(@PathVariable String id){
        if (StrUtil.isEmpty(id)){
            throw new EcoBootException("id不能为空");
        }
        chargeService.removeById(id);
        return Result.ok("ok");
    }

}
